package com.wpen.unit.infra.repository.job.impl;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wpen.unit.infra.mybatis.job.mapper.LockMapper;
import com.wpen.unit.infra.mybatis.job.po.LockPo;
import com.wpen.unit.infra.mybatis.job.po.LockPo.LockColumns;
import com.wpen.unit.infra.repository.job.LockRepository;

/**
 * 调度并发锁维护.
 * 
 * @author pg
 *
 */
@Repository
@Transactional
public class LockRepositoryImpl extends ServiceImpl<LockMapper, LockPo> implements LockRepository{
    
    @Override
    public LockPo queryForUpdate(String lockKey) {
        QueryWrapper<LockPo> queryWrapper = Wrappers.query();
        queryWrapper.eq(LockColumns.LOCK_NAME.name(), lockKey);
        queryWrapper.last(" FOR UPDATE");
		return super.getOne(queryWrapper);
    }
   
    
    @Override
    public boolean insert(LockPo lockPo) {
        return super.save(lockPo);
    }


}
